﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Phone.Controls;
using Microsoft.Unsupported;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
using System.IO;
using System.IO.IsolatedStorage;
using Microsoft.Xna.Framework.Media;
using com.google.zxing;
using System.Text;

namespace iLikeWine
{
    public partial class Ver_Qr_Code_Search : PhoneApplicationPage
    {
        BitmapImage tintoImage = new BitmapImage(new Uri("/iLikeWine;component/Images/vinho_tinto.png", UriKind.Relative));
        BitmapImage brancoImage = new BitmapImage(new Uri("/iLikeWine;component/Images/vinho_branco.png", UriKind.Relative));
        BitmapImage roseImage = new BitmapImage(new Uri("/iLikeWine;component/Images/vinho_rose.png", UriKind.Relative));
   
        private const string conn = @"isostore:/iLikeWine.sdf";
        Wine w = new Wine();
        
        public Ver_Qr_Code_Search()
        {
            InitializeComponent();

            IList<Wine> lista = this.GetWines();
            
         
            foreach (Wine w in lista)
            {

                if (w.Nome.Equals(qrcode_search.Qr_code))  //MainPage.ListSelect
                {
                    id.Text = w.ID.ToString();
                    nome.Text = w.Nome;
                    ano.Text = w.Ano;
                    regiao.Text = w.Regiao;
                    if (w.Tipo.Equals("Tinto"))
                    {

                        tipo.Text = "Tinto";
                        imageTipo.Source = tintoImage;

                    }
                    else if (w.Tipo.Equals("Branco"))
                    {
                        tipo.Text = "Branco";
                        imageTipo.Source = brancoImage;

                    }
                    else
                    {
                        tipo.Text = "Rosé";
                        imageTipo.Source = roseImage;
                    }
                    //tipo.Text = w.Tipo;
                    textBlock7.Text = w.Ranking + "/10";
                    w_w_w.Text = w.Www;
                    //--> FOTO
                    //image1.DataContext = w.Fotografia;

                    //<-- FOTO
                    //
                    comentario.Text = w.Comentario;


                }
            }
           


        }


       

        public IList<Wine> GetWines()
        {
            IList<Wine> lista = null;
            using (var ctx = new iLikeWineDataContext(conn))
            {
                IQueryable<Wine> query = ctx.Wines;
                //IQueryable<Wine> query = from ctx in ctx.Wines select w ;
                lista = query.ToList();
            }

            return lista;
        }

       
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Ajuda.xaml", UriKind.RelativeOrAbsolute));
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.RemoveBackEntry();
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
        }
    }
}